package cn.gh.duboo.demo.consumer.config;

import cn.gh.duboo.demo.controller.blog.BlogController;
import cn.gh.duboo.demo.controller.common.CommonController;
import cn.gh.duboo.demo.model.Blog;
import com.jfinal.config.*;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.TableInitKit;
import com.jfinal.plugin.spring.SpringPlugin;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2015/9/17.
 */
public class DemoConsumerConfig extends JFinalConfig {
    @Override
    public void configConstant(Constants constants) {
        constants.setDevMode(true);
    }

    @Override
    public void configRoute(Routes routes) {
        routes.add("/", CommonController.class);
        routes.add("/blog", BlogController.class);
    }

    @Override
    public void configPlugin(Plugins plugins) {
        plugins.add(new SpringPlugin());
    }

    @Override
    public void configInterceptor(Interceptors interceptors) {

    }

    @Override
    public void configHandler(Handlers handlers) {
        handlers.add(new ContextPathHandler("cxt"));
    }

    @Override
    public void afterJFinalStart() {
        Map<String, Class<?>> blogColumnMap = new HashMap<String, Class<?>>();
        blogColumnMap.put("id", Integer.class);
        blogColumnMap.put("title", String.class);
        blogColumnMap.put("content", String.class);

        TableInitKit.init("blog", Blog.class, blogColumnMap);

        System.out.println("Blog表字段模拟完成。");

        System.out.println("Demo consumer for Dubbo启动完成。");
    }
}
